package com.gitee.wsl.mathematics.geometry.d2.line.ext

import com.gitee.wsl.mathematics.coordinate.d2.Coordinate2
import com.gitee.wsl.mathematics.geometry.d2.line.LineShape2d


/** Extends the length of the segment by the given [length].
 * @since openrndr 0.4.4
 * */
fun<T:Number,V: Coordinate2<T, V>> LineShape2d<T, V>.extendBy(length: T, anchorT: Double = 0.5): LineShape2d<T, V> {
    val tangent = direction.normalized
    return create(a - tangent * length * (1.0-anchorT), b + tangent * length * anchorT)
}

/** Extends the length of the segment to the given [targetLength].
 * @since openrndr 0.4.4
 * */
fun<T:Number,V: Coordinate2<T, V>> LineShape2d<T, V>.extendTo(targetLength: T, anchorT: Double = 0.5) = extendBy(targetLength - length, anchorT)
